package com.eugene.shiftscalendar;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by Eugene on 24.03.14.
 */
public class DateInfo {
    static int getDateInfo(Date date, Context context){
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
        String name = sdf.format(date);
        return sp.getInt(name,-1);
    }

    static void setDateInfo(Date date, int info, Context context) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
        String name = sdf.format(date);
        sp.edit().putInt(name, info).apply();
    }

    static int getDateInfo(Calendar cal, Context context){
        cal.set(Calendar.HOUR_OF_DAY, 1);
        cal.set(Calendar.MINUTE, 1);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        Date date = new Date(cal.getTimeInMillis());
        return getDateInfo(date, context);
    }

    static void setDateInfo(Calendar cal, int info, Context context){
        cal.set(Calendar.HOUR_OF_DAY, 1);
        cal.set(Calendar.MINUTE, 1);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        Date date = new Date(cal.getTimeInMillis());
        setDateInfo(date, info, context);
    }

    static Date initDate(Date date){
        date.setHours(1);
        date.setMinutes(1);
        date.setSeconds(0);
        return date;
    }
}
